import request from "./request";
class Plugin
{
    /**
     * 是否可以运行插件
     * @param name 插件名称标识
     * address用户地址管理
     */
   tryRun(name)
   {
        this.name = name;
        return new Promise((success)=>{
            this.getApi(name)
                .then((api)=>{
                    request("setting/tryRun",{},api)
                        .then((res)=>{
                            if(res.data.status === "success"){
                                success(true);
                            }else{
                                success(false);
                            }
                        })
                })
        });
   }

    /**
     * 获取插件请求的API
     */
   getApi(name)
   {
       return new Promise((success)=>{
           request("plugins/getApi",{
               name
           })
               .then((res)=>{
                   if(res.data.status === "success"){
                       this.api = res.data.data;
                       success(res.data.data);
                   }
               });
       });
   }
}

export default new Plugin();
